﻿function threeLevel() {
    //debugger;

    CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerState.splice(1, 1);
    CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerCity.splice(1, 1);
    CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerDistrict.splice(1, 1);

    var state = ""; var city = ""; var district = "";
    if (CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerState !== "") {//编辑初始化
        // initComplexArea('CPForm_12420', 'CPForm_12421', 'CPForm_12468', area_array, sub_array, '44', '0', '0');
      
        state = CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerState;
        city = CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerCity;
        district = CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerDistrict;
    }
        
        var ItemsState = ProvinceArray(area_array);
        var stateid;
        for (var i = 0; i < ItemsState.length; i++) {
            var stateObj = new Object();
            stateObj.textEx = trim(ItemsState[i].text);
            stateObj.valueEx = trim(ItemsState[i].value.toString());
            stateObj.listRelateEx = "";
            CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerState.push(stateObj);
            if (ItemsState[i].text === state) stateid = ItemsState[i].value.toString();
        }
        var ItemsCity = changeComplexProvinceArray(stateid, sub_array);
        var cityid = "";
        for (var j = 0; j < ItemsCity.length; j++) {
            var cityObj = new Object();
            cityObj.textEx = trim(ItemsCity[j].text);
            cityObj.valueEx = trim(ItemsCity[j].value.toString());
            cityObj.listRelateEx = "";
            CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerCity.push(cityObj);
            if (ItemsCity[j].text === city) cityid = ItemsCity[j].value.toString();
        }

        var Items = chanageCityArray(cityid);
        // CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerDistrict.splice(0, 1);
        var districtid = "";
        for (var t = 0; t < Items.length; t++) {
            var districtObj = new Object();
            districtObj.textEx = trim(Items[t].text);
            districtObj.valueEx = trim(Items[t].value.toString());
            districtObj.listRelateEx = "";
            CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerDistrict.push(districtObj);
            // $("#CPForm_12468").append("<option value='" + Items[t].value + "'>" + Items[t].text + "</option>");
            if (Items[t].text === district) districtid = Items[t].value.toString();


        }

        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerState = stateid;
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerCity = cityid;
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerDistrict = districtid;
   // }

    //省份change事件
    $("#CPForm_12420").change(function () {
        changeComplexProvince(this.value, sub_array, 'CPForm_12421', 'CPForm_12468');
    });
    $("#CPForm_13213").change(function () {
        changeComplexProvince(this.value, sub_array, 'CPForm_13214', 'CPForm_13256');
    });

    //城市change事件
    $("#CPForm_12421").change(function () {
        changeCity(this.value, 'CPForm_12468', 'CPForm_12468');
    });
    $("#CPForm_13214").change(function () {
        changeCity(this.value, 'CPForm_13256', 'CPForm_13256');
    });
   
    UpdateLoadDOM();
    debugger;
    CPFormGlobal_FormObj.Data.YW_OrderDetail_ValueAdded_Content.splice(0, 1);
    $("select[data-fieldname='ValueAdded_Content']").find('option').remove();
    $("select[data-fieldname='ValueAdded_Content']")[0].textContent = "";
    //$("select[data-fieldname='ValueAdded_Content']").find('option').remove();
    var data = [{ id: 1, text: '断喙' }, { id: 2, text: '传支' }, { id: 3, text: '法氏囊' }, { id: 4, text: '公鸡剪冠' }];
    $("select[data-fieldname='ValueAdded_Content']").select2({
        language: 'zh-CN', //中文
        data: data,  //初始化数据
        placeholder: '请选择',  //提示语
        multiple: true  //开启多选
    });
    //$("select[data-fieldname='ValueAdded_Content'] option:first").remove();
    $("select[data-fieldname='ValueAdded_Content']").on("change", function (e) {
        debugger
        $("li[class='select2-selection__choice'][title='']").remove();
        if ($("select[data-fieldname='ValueAdded_Content'] option:first").text() == "")
            $("select[data-fieldname='ValueAdded_Content'] option:first").remove();
    });

    //默认绑定项目内容
    $.each(CPFormGlobal_FormObj.Data.YW_OrderDetail, function (dIndex, dObj) {
        var datavalue = dObj.ValueAdded_Content.split(',');
        var content = new Array();
        $.each(datavalue, function (nIndex, nObj) {
            debugger
            $("select[data-fieldname='ValueAdded_Content'] option:contains(" + nObj + ")").each(function () {
                debugger;
                if ($(this).text() == nObj) {
                    content[nIndex] = $(this).val();     
                    //$("select[data-fieldname='ValueAdded_Content'] option:contains(" + nObj + ")").attr('selected', true);
                }
            });
        });
        $("select[data-fieldname='ValueAdded_Content']").val(content).trigger("change");
    });


    
}

function trim(str) { //删除左右两端的空格
    return str.replace(/(^s*)|(s*$)/g, "");
}


function saveBegin() {
    debugger


    var phone = $("input[data-fieldname='SalesmanTel']").val();
    if (!(/^1[34578]\d{9}$/.test(phone)) && phone!="") {
        alert("业务员电话格式有误，请重填");
        return false;
    }
    var mobile = $("input[data-fieldname='CustomerMobile']").val();
    if (!(/^1[34578]\d{9}$/.test(mobile)) && mobile != "") {
        alert("收货人的手机号码格式有误，请重填");
        return false;
    }
    var $CPForm_12420 = $("select[data-fieldname='CustomerState']");
    var $CPForm_12421 = $("select[data-fieldname='CustomerCity']");
    var $CPForm_12422 = $("select[data-fieldname='CustomerDistrict']");
    if ($CPForm_12420.find("option:selected").val() === "0") {
        CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerState = "";
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerState = "";
    } else {
        CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerState = $CPForm_12420.find("option:selected").text();
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerState = $CPForm_12420.find("option:selected").text();
    }
    if ($CPForm_12421.find("option:selected").val() === "0") {
        CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerCity = "";
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerCity = "";
    } else { 
    CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerCity = $CPForm_12421.find("option:selected").text();
    CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerCity = $CPForm_12421.find("option:selected").text();
}
    if ($CPForm_12422.find("option:selected").val() === "0") {
        CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerDistrict = "";
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerDistrict = "";
    } else {
        CPFormGlobal_FormObj.Data.YW_OrderInfo_CustomerDistrict = $CPForm_12422.find("option:selected").text();
        CPFormGlobal_FormObj.Data.YW_OrderInfo.CustomerDistrict = $CPForm_12422.find("option:selected").text();
    }

    var SaleDept = $("select[data-fieldname='SaleDeptId']");
    if (SaleDept.find("option:selected").val() !== "0") {
        CPFormGlobal_FormObj.Data.YW_OrderInfo.SaleDeptId = SaleDept.val();
    }

    //服务内容
    $.each($("select[data-fieldname='ValueAdded_Content']"), function (index, obj) {
        debugger
        var text = "";
        //$.each($(obj).find("option"), function (oIndex, oObj) {
        //    if ($(oObj).text() == "") return true;
        //    if ($(oObj)[0].selected == true) text += $(oObj).text() + ",";
        //});
        $(".select2-selection__rendered li").each(function (oIndex) {
            if ($(this)[0].title == "") return true;
            text += $(this)[0].title + ",";
        });

        text = text.substring(0, text.length - 1);
        CPFormGlobal_FormObj.Data.YW_OrderDetail[index].ValueAdded_Content = text;     
    });

    //主表中总雏鸡数与总路耗绑定

    var total = 0;
    var roadloss = 0;
    $.each($("input[data-fieldname='BuyChickCount']"), function (index, obj) {
        total += parseInt(obj.value);
    });
    $.each($("input[data-fieldname='MaleBuyChickCount']"), function (index, obj) {
        total += parseInt(obj.value);
    });
    $.each($("input[data-fieldname='LossCount']"), function (index, obj) {
        roadloss += parseInt(obj.value);
    });
    CPFormGlobal_FormObj.Data.YW_OrderInfo.TotalCount = total;
    CPFormGlobal_FormObj.Data.YW_OrderInfo.OrderRoadLoss = roadloss;
}


function varietyChange(obj) {
    debugger
    var index = obj.$index;
    var $CPForm_12455 = document.getElementById("CPForm_12455_" + index);
    if ($CPForm_12455==undefined) {
        $CPForm_12455 = document.getElementById("CPForm_13247_" + index);
    }
    var childList = $CPForm_12455.children;
    var text;
    for (var i = 0; i < childList.length; i++) {
        if ($CPForm_12455.value == childList[i].value) { text = childList[i].innerText; break; }
    }

    CPFormGlobal_FormObj.Data.YW_OrderDetail[index].VarietyName = text;
}

function goodsChange(obj) {
    debugger
    var index = obj.$index;
    var $CPForm_12457 = document.getElementById("CPForm_12457_" + index);
    if ($CPForm_12457 == undefined) {
        $CPForm_12457 = document.getElementById("CPForm_13249_" + index);
    }
    var childList = $CPForm_12457.children;
    var text;
    for (var i = 0; i < childList.length; i++) {
        if ($CPForm_12457.value == childList[i].value) { text = childList[i].innerText; break; }
    }

    CPFormGlobal_FormObj.Data.YW_OrderDetail[index].GoodsName = text;
}

//销售部发生改变事件
function SaleDeptChange(obj) {
    debugger
    var SaleDeptId = $("select[data-fieldname='SaleDeptId']");
    var childList = SaleDeptId[0].children;
    var text;
    for (var i = 0; i < childList.length; i++) {
        if (SaleDeptId.val() == childList[i].value) {
            text = childList[i].innerText; break;
        }
    }

    CPFormGlobal_FormObj.Data.YW_OrderInfo.SaleDeptName = text;
   // CPFormGlobal_FormObj.Data.YW_OrderInfo.SaleDeptId = SaleDeptId.val();
}

//公司名称控件改变事件
function OrgIdChange(obj) {
    debugger
    var OrgId = $("select[data-fieldname='OrgId']");
    var childList = OrgId[0].children;
    var text;
    for (var i = 0; i < childList.length; i++) {
        if (OrgId.val() == childList[i].value) {
            text = childList[i].innerText; break;
        }
    }

    CPFormGlobal_FormObj.Data.YW_OrderInfo.OrgName = text;
    //CPFormGlobal_FormObj.Data.YW_OrderInfo.OrgId = OrgId.val();

    var selectSource = new Object();
    selectSource.FieldEnumDataIns = "CPOrganIns";
    var $CPForm_12437 = $("select[data-fieldname='type']").val();
    
    if ($CPForm_12437 == "父母代")
        selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId))  as value from [dbo].[CP_Dep]    where ParentId = 100000029 and DepType = 3";
    else
        selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId))  as value from [dbo].[CP_Dep]    where ParentId =" + OrgId.val() + " and DepType = 3   order by DepId";
    //绑定基地信息
    var url = "/api/HatchRoom/GetSourceInfo";


    $.ajax({
        type: "POST",
        url: url,
        data: JSON.stringify(selectSource),
        contentType: 'application/json',
        success: function (data) {
            if (data.length !== 0) {
                $("select[data-fieldname='SaleDeptId']").find("option").remove();
                //json字符串转化为json对象
                data = eval('(' + data + ')');
                data = eval('(' + data.Column + ')');
                $("select[data-fieldname='SaleDeptId']").append("<option value ='0' selected='selected'>==请选择==</option>");
                for (var i = 0; i < data.length; i++) {
                    var columnObj = data[i];
                    var html = "<option value ='" + columnObj.valueEx + "'> " + columnObj.textEx + "</option>";
                    $("select[data-fieldname='SaleDeptId']").append(html);
                }

                //$("#" + baseid_id + " option:first").remove();
            }
        }
    });
}

function CPGridData() {
    debugger
    if (parent.CPRefresh !== undefined) parent.CPRefresh();
    if (parent.CPGridRefresh !== undefined) parent.CPGridRefresh();
    if (parent.CloseNewModel !== undefined) parent.CloseNewModel();
}

function DelParents() {
    var sValue = CPGridGetSelChkData();
    if (sValue == "") {
        alert("请选择要删除的数据！");
        return false;
    }
    if (confirm("确实要删除选中的数据吗？")) {

        //业务数据删除
        var deleteUrl = CPWebRootPath + "/api/ParentsGeneration/DeleteBusinessGridData?GridCode=" + CPGridGlobal_GridCode + "&CurUserId=" + CPCurUserId + "&CurUserIden=" + CPCurUserIden;
        deleteUrl += "&OrderIds=" + sValue;
        
        $.getJSON(deleteUrl, function (data) {
            if (data.Result == false) {
                alert("删除失败，详细信息：" + data.ErrorMsg);
                return false;
            }  
            else {
                var Url = CPWebRootPath + "/api/ParentsGeneration/DeleteGridData?GridCode=" + CPGridGlobal_GridCode + "&CurUserId=" + CPCurUserId + "&CurUserIden=" + CPCurUserIden;
                Url += "&DataPks=" + sValue;
                //为了表达式，需要把URL里其它字段再加上
                //再加其它参数
                var sResultArray = CPGetQueryString();
                for (var mm = 0; mm < sResultArray.length; mm++) {
                    var tempSarray = sResultArray[mm].split('=');
                    if (tempSarray[0].toLowerCase() == "gridcode"
                        || tempSarray[0].toLowerCase() == "curuserid"
                        || tempSarray[0].toLowerCase() == "curuseriden"
                        || tempSarray[0].toLowerCase() == "datapks"
                    )
                        continue;
                    Url += "&" + sResultArray[mm];
                }
                $.getJSON(Url, function (data) {
                    if (data.Result == false) {
                        alert("删除失败，详细信息：" + data.ErrorMsg);
                        return false;
                    } else {
                        alert("删除成功！");
                        CPGridRefresh();
                    }
                });
               
            }
        }); 
    }
}

//打开父母代
function openPlan(OrderCode, staute) {
    //debugger
    var tmpUrlTmp;
    if (staute > 0)
        tmpUrlTmp = "/Plat/Form/FormView?FormCode=Form201810180950000001&SceneCode=Scene201810180951310001&ViewCode=View201810180951310001&DeviceType=1&InitGroupCode=Group201810241625210001&RightGroupCode=Group201811231037140001&PKValues=" + OrderCode;
    else
        tmpUrlTmp = "/Plat/Form/FormView?FormCode=Form201810180950000001&SceneCode=Scene201810180951310001&ViewCode=View201810180951310001&DeviceType=1&InitGroupCode=Group201810191408520001&PKValues=" + OrderCode;
    var OpenWinWidth = 1000;
    var OpenWinHeight = 700;
    tmpUrlTmp = FormatUrlForOpenNewModel(tmpUrlTmp, "top", "");
    top.OpenNewModel(tmpUrlTmp, "设置车辆", OpenWinWidth, OpenWinHeight);
}

//打开商品代
function openFrom(OrderCode, staute) {  

    var tmpUrlTmp;
    if (staute > 0)
        tmpUrlTmp = "/Plat/Form/FormView?FormCode=Form201901161510110001&SceneCode=Scene201901161525390001&ViewCode=View201901161535100001&DeviceType=1&InitGroupCode=Group201901161627200001&RightGroupCode=Group201811231037140001&PKValues=" + OrderCode;
    else
        tmpUrlTmp = "/Plat/Form/FormView?FormCode=Form201901161510110001&SceneCode=Scene201901161525390001&ViewCode=View201901161535100001&DeviceType=1&InitGroupCode=Group201901161627200001&PKValues=" + OrderCode;
    var OpenWinWidth = 1000;
    var OpenWinHeight = 700;
    tmpUrlTmp = FormatUrlForOpenNewModel(tmpUrlTmp, "top", "");
    top.OpenNewModel(tmpUrlTmp, "设置车辆", OpenWinWidth, OpenWinHeight);
}

//代次发生变化，调整销售部数据源
function typeChange(typeval) {
    debugger
    var selectSource = new Object();
    selectSource.FieldEnumDataIns = "CPOrganIns";
    //var $CPForm_12437 = $("select[data-fieldname='type']").val();
    if (typeval == "父母代")
        selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId)) as value from [dbo].[CP_Dep]  where DepType=2 and DepId=100000029";
    else
        selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId)) as value from [dbo].[CP_Dep]  where DepType=2 and DepId!=100000029  order by DepId";
    //绑定基地信息
    var url = "/api/HatchRoom/GetSourceInfo";


    $.ajax({
        type: "POST",
        url: url,
        data: JSON.stringify(selectSource),
        contentType: 'application/json',
        success: function (data) {
            if (data.length !== 0) {
                $("select[data-fieldname='OrgId']").find("option").remove(); 
                //json字符串转化为json对象
                data = eval('(' + data + ')');
                data = eval('(' + data.Column + ')');
                $("select[data-fieldname='OrgId']").append("<option value ='0' selected='selected'>==请选择==</option>");
                for (var i = 0; i < data.length; i++) {
                    var columnObj = data[i]; var html;
                    if (CPFormGlobal_FormObj.Data.YW_OrderInfo.OrgId == columnObj.valueEx)
                        html = "<option value ='" + columnObj.valueEx + "'selected='selected' > " + columnObj.textEx + "</option>";
                    else
                        html = "<option value ='" + columnObj.valueEx + "'> " + columnObj.textEx + "</option>";
                    $("select[data-fieldname='OrgId']").append(html);
                }

                //$("#" + baseid_id + " option:first").remove();
            }
        }
    });

    //默认选中
    var OrgName = $("select[data-fieldname='OrgId']");
    if (typeval == "父母代") OrgName.val = "100000029";

}

function UpdateLoadDOM() {

    //debugger;
    var selectSource = new Object();
    selectSource.FieldEnumDataIns = "CPOrganIns";
    var $CPForm_12437 = CPFormGlobal_FormObj.Data.YW_OrderInfo.type;
    if ($CPForm_12437 == "父母代")
        selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId))  as value from [dbo].[CP_Dep]    where ParentId = 100000029 and DepType = 3";
    else {
        if (CPFormGlobal_FormObj.Data.YW_OrderInfo.OrgId == null || CPFormGlobal_FormObj.Data.YW_OrderInfo.OrgId =="")
            selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId))  as value from [dbo].[CP_Dep]    where ParentId != 100000029 and DepType = 3   order by DepId";
            else
            selectSource.FieldEnumDataSource = "select LTRIM(RTRIM(depname)) as text,LTRIM(RTRIM(depId))  as value from [dbo].[CP_Dep]    where ParentId =" + CPFormGlobal_FormObj.Data.YW_OrderInfo.OrgId + " and DepType = 3   order by DepId";
    }
    //绑定基地信息
    var url = "/api/HatchRoom/GetSourceInfo";


    $.ajax({
        type: "POST",
        url: url,
        data: JSON.stringify(selectSource),
        contentType: 'application/json',
        success: function (data) {
            if (data.length !== 0) {
                $("select[data-fieldname='SaleDeptId']").find("option").remove();
                //json字符串转化为json对象
                data = eval('(' + data + ')');
                data = eval('(' + data.Column + ')');
                $("select[data-fieldname='SaleDeptId']").append("<option value ='0'>==请选择==</option>");
                var SaleDeptId = CPFormGlobal_FormObj.Data.YW_OrderInfo.SaleDeptId;
                for (var i = 0; i < data.length; i++) {
                    var columnObj = data[i];
                    var html;
                    if (columnObj.valueEx === SaleDeptId)
                        html = "<option value ='" + columnObj.valueEx + "' selected='selected'> " + columnObj.textEx + "</option>";
                    else
                        html = "<option value ='" + columnObj.valueEx + "'> " + columnObj.textEx + "</option>";
                    $("select[data-fieldname='SaleDeptId']").append(html);
                }

            }
        }
    });
}


//批量导入数据
var index;
function BatchImport() {
    //页面层
    index = layer.open({
        type: 1,//Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加 载层）4（tips层）,
        title: '上传框',   //标题
        // skin: 'layui-layer-rim', //加上边框
        skin: 'layer-ext-moon',//皮肤
        shade: 0.4,   //遮罩透明度
        area: ['350px', '100px'], //宽高
        content: '<div><input type="file" onchange="importf(this)" style="padding-top:10px;padding-left:100px;width:70%"></div><div id="demo"></div>'
    });

}
/*
 FileReader共有4种读取方法：
 1.readAsArrayBuffer(file)：将文件读取为ArrayBuffer。
 2.readAsBinaryString(file)：将文件读取为二进制字符串
 3.readAsDataURL(file)：将文件读取为Data URL
 4.readAsText(file, [encoding])：将文件读取为文本，encoding缺省值为'UTF-8'
              */
var wb;//读取完成的数据
var rABS = false; //是否将文件读取为二进制字符串

//导入文件
function importf(obj) {
    debugger
    if (!obj.files) {
        return;
    }
    var f = obj.files[0];
    var reader = new FileReader();
    reader.onload = function (e) {
       
        debugger
        var data = e.target.result;
        if (rABS) {
            wb = XLSX.read(btoa(fixdata(data)), {//手动转化
                type: 'base64'
            });
        } else {
            wb = XLSX.read(data, {
                type: 'binary'
            });
        }
        //只能上传excel
        if (wb.Props ==undefined ) {
            layer.msg('必须上传excel文件', { time: 2000, shade: [0.5, '#000', true] });
            return;
        }
        if (wb.Props.Application === "Microsoft Excel")
            layer.msg('正在上传。。。', { icon: 16, time: 100000, shade: [0.5, '#000', true] });

        //wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
        //wb.Sheets[Sheet名]获取第一个Sheet的数据
        //document.getElementById("demo").innerHTML= JSON.stringify( XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]) );
        data = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
        data = split_array(data, 2000);
        var url = "/api/ParentsGeneration/BatchImport";
        var inputObj = new Object();
        inputObj.GridCode = CPGridGlobal_GridObj.GridCode;
        inputObj.CurUserId = CPCurUserId;
        inputObj.CurUserIden = CPCurUserIden;
        inputObj.ExcelItemList = data[0];

        //发送到后台
       // var status = 0;
       // for (var i = 0; i < data.length; i++) {
           // console.log(data[i]);

            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(inputObj),
                contentType: 'application/json',
                success: function (result) {
                    console.log(result);
                    if (result.Result === true) {
                        layer.msg('上传成功', { time: 2000 });
                        //关闭动作的关键代码
                        layer.close(index); //再执行关闭       
                        CPGridRefresh();
                    } else {
                        alert("不合法！错误信息如下：" + result.ErrorMsg);
                        //return false;
                    }
                    //成功获取一般处理程序响应后执行的代码
                },
                error: function (err) {
                    //收到一般处理程序响应失败后执行的代码
                }
            });
        //}
        //结束
       // console.log(status);
    };
    if (rABS) {
        reader.readAsArrayBuffer(f);
    } else {
        reader.readAsBinaryString(f);
    }

}
function split_array(arr, len) {
    var a_len = arr.length;
    var result = [];
    for (var i = 0; i < a_len; i += len) {
        result.push(arr.slice(i, i + len));
    }
    return result;
}
function fixdata(data) { //文件流转BinaryString
        var o = "",
            l = 0,
            w = 10240;
        for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
        o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
        return o;
}


//下载模板[商品代]
function SPDDownLoadTemp() {
    window.location.href = "/Plat/Temp/商品代新增订单模板.xlsx";
}
//下载模板[父母代]
function DownLoadTemp() {
    window.location.href = "/Plat/Temp/父母代新增订单模板.xlsx";
}
   
